package org.kele.servicecomb.comsumer.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.servicecomb.provider.pojo.RpcReference;
import org.apache.servicecomb.provider.rest.common.RestSchema;
import org.kele.servicecomb.api.rpc.BmiCalculateForRestRpc;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@RestSchema(schemaId = "ComsumController")
@RequestMapping("/v1")
public class ComsumController {

    @RpcReference(schemaId = "BmiController", microserviceName = "boot-provider")
    BmiCalculateForRestRpc bmiCalculateForRestRpc;

    @GetMapping("/bmi/{height}/{weight}")
    public double calculate(@PathVariable("height") double height,
                            @PathVariable("weight") double weight) {
        log.info("转发请求...{},{}", height, weight);
        return bmiCalculateForRestRpc.calculate(height, weight);
    }

    @GetMapping("/testex")
    public String testEx(){
        return bmiCalculateForRestRpc.testEx();
    }
}
